﻿using System.Linq;
using Medianamik.Core.Sugar;
using NUnit.Framework;

namespace Tests.Unit.Medianamik.Core
{
    [TestFixture]
    public class PagingTests
    {
        [Test]
        public void NoLittlePointsAtAll()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 5, 5, 3);

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.False);
            Assert.That(result.HasSuffix, Is.False);
        }

        [Test]
        public void LittlePointsToTheLeft()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 10, 5, 8);

            CollectionAssert.AreEqual(new[] { 6, 7, 8, 9, 10 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.True);
            Assert.That(result.HasSuffix, Is.False);
        }

        [Test]
        public void LittlePointsToTheLeft2()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 10, 5, 10);

            CollectionAssert.AreEqual(new[] { 6, 7, 8, 9, 10 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.True);
            Assert.That(result.HasSuffix, Is.False);
        }

        [Test]
        public void LittlePointsToTheRight()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 10, 5, 1);

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.False);
            Assert.That(result.HasSuffix, Is.True);
        }

        [Test]
        public void LittlePointsToTheRight2()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 10, 5, 2);

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.False);
            Assert.That(result.HasSuffix, Is.True);
        }

        [Test]
        public void LittlePointsOnBothSides()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 10, 5, 4);

            CollectionAssert.AreEqual(new[] { 2, 3, 4, 5, 6 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.True);
            Assert.That(result.HasSuffix, Is.True);
        }

        [Test]
        public void LittlePointsOnBothSides2()
        {
            var result = PagingUtil.GetPagesToDisplay("", "", 5, 3, 3);

            CollectionAssert.AreEqual(new[] { 2, 3, 4 }, result.Pages.Select(p => p.Index).ToArray());
            Assert.That(result.HasPrefix, Is.True);
            Assert.That(result.HasSuffix, Is.True);
        }
    }
}
